<?php

/**
 * Staff form.
 *
 * @package    erp-dnict
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class StaffForm extends BaseStaffForm
{
  public function configure()
  {
    $this->setWidgets(array(
        'reference'                 =>  new sfWidgetFormInput(),
        'name'                      =>  new sfWidgetFormInput(),
        'email'                     =>  new sfWidgetFormInput(),
        'birth_place'               =>  new sfWidgetFormInput(),
        'address'                   =>  new sfWidgetFormTextarea(),
        'id_number'                 =>  new sfWidgetFormInput(),
        'id_place_issue'            =>  new sfWidgetFormInput(),
        'id_date_issue'             =>  new sfWidgetFormInput(),
        'birthday'                  =>  new sfWidgetFormInput(),
        'contract_date'             =>  new sfWidgetFormInput(),
        'start_date'                =>  new sfWidgetFormInput(),
    ));

    $file_src = $this->getObject()->getReference().$this->getObject()->getName().'.jpeg';
    if ($this->getObject()->isNew())
    {
        $file_src = 'default.jpg';
    }
    $this->widgetSchema['photo'] = new sfWidgetFormInputFileEditable(array(
      'label'     => ' ',
      'file_src'  => '/'.sfConfig::get('app_photo_upload_dir').$file_src,
      'is_image'  => true,
      'edit_mode' => true,
      'template'  => '<div>%file%<br />%input%</div>',
    ));

    $this->widgetSchema->setLabels(array(
        'reference'                 =>  'Mã nhân viên:',
        'name'                      =>  'Họ tên:',
        'email'                     =>  'Email:',
        'birth_place'               =>  'Nơi sinh:',
        'address'                   =>  'Địa chỉ:',
        'id_number'                 =>  'Số CMND:',
        'id_place_issue'            =>  'Nơi cấp CMND:',
        'id_date_issue'             =>  'Ngày cấp CMND:',
        'photo'                     =>  'Hình đại diện:',
        'birthday'                  =>  'Ngày sinh:',
        'contract_date'             =>  'Ngày ký hợp đồng:',
        'start_date'                =>  'Ngày bắt đầu làm việc:',
    ));

    $this->setValidators(array(
        'reference'                 =>  new sfValidatorString(array('required' => true)),
        'name'                      =>  new sfValidatorString(array('required' => true)),
        'email'                     =>  new sfValidatorEmail(array('required' => true)),
        'birth_place'               =>  new sfValidatorString(array('required' => true)),
        'address'                   =>  new sfValidatorString(array('required' => true)),
        'id_number'                 =>  new sfValidatorString(array('required' => true)),
        'id_place_issue'            =>  new sfValidatorString(array('required' => true)),
        'birthday'                  =>  new sfValidatorDate(array('required' => true, 'date_output' => 'dd/mm/yy', 'date_format' => "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/")),
        'contract_date'             =>  new sfValidatorDate(array('required' => true, 'date_output' => 'dd/mm/yy', 'date_format' => "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/")),
        'start_date'                =>  new sfValidatorDate(array('required' => true, 'date_output' => 'dd/mm/yy', 'date_format' => "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/")),
        'id_date_issue'             =>  new sfValidatorDate(array('required' => true, 'date_output' => 'dd/mm/yy', 'date_format' => "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/")),
    ));

    $this->validatorSchema['photo'] = new sfValidatorFile(array(
            'mime_types' => array('image/jpeg', 'image/jpg'),
            'path' => sfConfig::get('app_photo_upload_dir'),
            'required' => false,
            ));
    $this->widgetSchema->setNameFormat('staff[%s]');
  }
}
